<template>
	<view class="app">
		<view class="panel">
			<view class="flex-col">
<!-- 				<view class="flex justify-between list" v-for="(item,index) in list.data">
					<view>{{item.openid}}</view>
					<view>{{item.isfollow?'关注':'取消关注'}}</view>
				</view> -->
				<view class="flex justify-center items-center">
					<button @click="startSend" v-if="!isStart">开始群发</button>
					<button @click="stopSend" v-else>停止群发</button>
				</view>
				<view class="flex justify-center bottomfiexd">
					<view>{{list.total}}个</view>
					<view style="margin-left: 16px;">成功{{sendCount.y}} / 失败{{sendCount.n}} /总{{sendCount.c}}</view>
					<view style="margin-left: 16px;">{{list.current_page}}/{{list.last_page}}页</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var that,App=getApp(),Comm=getApp().comm;
	export default {
		data() {
			return {
				list:{"total":0,"per_page":0,"current_page":0,"last_page":1,"data":[]},
				sendCount:{
					c:0,
					y:0,
					n:0
				},
				isStart:false,
			}
		},
		onLoad() {
			that=this;
		},
		methods: {
			sendMsg(){
				if(!this.isStart){
					return;
				}
				let limit=50,page=this.list.current_page+1;
				if(page>this.list.last_page){
					this.isStart=false;
					Comm.tips("已到最后一页");
					return;
				}
				Comm.http('/api/tool/sendmsg',{page:1,limit}).then(async res=>{
					that.list=res.data.data;
					console.log(that.list);
					that.sendCount.c+=res.data.count;
					that.sendCount.y+=res.data.success;
					that.sendCount.n+=res.data.fail;
					window.setTimeout(()=>{
						that.sendMsg();
					},100);
				});
			},
			startSend(){
				this.isStart=true;
				this.sendMsg();
			},
			stopSend(){
				this.isStart=false;
			}
		}
	}
</script>

<style lang="scss">
	.panel{
		.list{
			padding: 8px 0; border-bottom: 1px solid #f0f0f0;
		}
		.bottomfiexd{
			position: fixed; width: 100vw; height: 45px; line-height: 45px; left: 0; bottom: 0; background-color: #ffffff; border-top: #f0f0f0 2px solid;
		}
	}
</style>
